package com.xuanyuanxinyu.core.base

import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch

/**
 * @FileName:
 * @Description:
 * @author ken.luo
 * @date 2023/4/4
 * @version V1.0
 * @email 424533553@qq.com
 */
open class BaseActivity : AppCompatActivity(),CoroutineScope by MainScope() {
    private val job = Job()
    val scope by lazy { CoroutineScope(job) }
    
    /**
     * 从Main线程中执行任务
     */
    private fun startTaskFromMain(block : (String) -> Unit) {
        launch { block.toString() }
        
    }
    
    
    override fun onDestroy() {
        job.cancel()
        scope.cancel()
        cancel()
        super.onDestroy()
    }
    
}